import 'package:json_annotation/json_annotation.dart';
import 'package:xindong/common/xindong_types.dart';
import 'package:xindong/utils/xindong_text_util.dart';

part 'xindong_user.g.dart';

@JsonSerializable()
class XinDongUser {
  dynamic id;
  dynamic userid;
  dynamic user_id;
  String? age; // 年龄
  String? name; // 昵称
  String? sex = Gender.none;

  // 头像
  String? avatar;
  String? head_100;
  String? head_portrait;

  bool? canSayHello; // 能搭讪
  int? sayHelloTime; // 搭讪时间

  XinDongUser();

  String get uid {
    if (userid != null) return "$userid";
    if (user_id != null) return "$user_id";
    if (id != null) return "$id";
    return "0";
  }

  // 获取显示名称
  String get getName {
    if (TextUtil.isEmpty(name)) {
      return uid;
    }
    return name!;
  }

  // 获取
  String get getAvatar {
    if (!TextUtil.isEmpty(head_portrait)) {
      return head_portrait!;
    }
    if (!TextUtil.isEmpty(head_100)) {
      return head_100!;
    }
    if (!TextUtil.isEmpty(avatar)) {
      return avatar!;
    }
    return "";
  }

  // 男
  bool get isMale {
    return sex == Gender.male;
  }

  // 女
  bool get isFemale {
    return sex == Gender.female;
  }

  factory XinDongUser.fromJson(Map<String, dynamic> json) => _$XinDongUserFromJson(json);

  Map<String, dynamic> toJson() => _$XinDongUserToJson(this);
}
